/**
 * Created by hjc_0 on 2016/7/29.
 */

var AreaObj = {
    tms : 0,

    setSelectValue: function(select, value) {
        this.tms++;
        if (value != '0' && value) {
            select.val(value);
            select.val() != value ? setTimeout(function () {
                this.tms < 20 ? setSelectValue(select, value) : select.val('0');
            }, 50) : select.trigger('change');
        }
    },

    areaChoose: function(){
        var pv = $('select[name="province"]');
        var ct = $('select[name="city"]');
        //var ae = $('select[name="area"]');

        var opt = '<option value="0">请选择</option>';
        var pvStr = opt;
        for (var i = 0, len = areas.provces.length; i < len; i++) {
            pvStr += ('<option value="' + areas.provces[i].id + '">' + areas.provces[i].name + '</option>');
        }
        pv.html(pvStr);
        pv.change(function () {
            var ctStr = opt;
            var vls = $(this).val();
            for (var i = 0, len = areas.city.length; i < len; i++) {
                (areas.city[i].pid == vls) && (ctStr += ('<option value="' + areas.city[i].id + '">' + areas.city[i].name + '</option>'));
            }
            ct.html(ctStr).val('0').trigger('change');
        })
        /*ct.change(function () {
            var aeStr = opt;
            var vls = $(this).val();
            for (var i = 0, len = areas.dist.length; i < len; i++) {
                (areas.dist[i].cid == vls) && (aeStr += ('<option value="' + areas.dist[i].id + '">' + areas.dist[i].name + '</option>'));
            }
            ae.html(aeStr);
        })*/
        this.setSelectValue(pv, pv.attr('aid'));
        this.setSelectValue(ct, ct.attr('aid'));
        //this.setSelectValue(ae, ae.attr('aid'));
    }
};